
version 15
capture log close
set more off
clear
clear matrix
clear mata

if c(username)=="WB485280" {
		glo rootdir		"C:\Users\wb485280\OneDrive - WBG\radicalization"
		}
if c(username)=="WB382635" {
		glo rootdir		"C:\Users\wb382635\Dropbox\Unemp & daesh"
		}
if c(username)=="WB452275" {
		glo rootdir		"C:\Users\WB452275\Dropbox\Projects\Unemp & daesh"
		}
if c(username)=="sarurchaudhary" {
		glo rootdir		"/Users/sarurchaudhary/Dropbox/Unemp & daesh"
		}
if c(username)=="kartikabhatia" {
			glo rootdir		"/Users/kartikabhatia/Dropbox/Before2019/Unemp & daesh"
			}
			
		glo	datadir     "${rootdir}/Data/Raw data"
		glo outdir		"${rootdir}/Data/Working datasets"
		glo dodir		"${rootdir}/Dofiles"
        
		cd "${outdir}"
		
		
	    log using i2d2_prep, replace t



* ------------------------------------------------------------------------------
* Date : July 2017 [chkd oct 2021]


* Project : Mena Economic Monitor, Fall 2016 edition (MNACE, The World Bank)


* This do file prepares the WDI database for merge

* Database used : i2d2_raw.dta


* Output : i2d2.dta

* ------------------------------------------------------------------------------
		
use "${datadir}/i2d2_raw.dta", clear
codebook ccode year edulevel1 unemp_rate

* keep only male (later ask david to generate total unemployment as well?)

keep if gender==1
codebook ccode year unemp_rate

* keep education levels we want (for now: completed primary, completed secondary, Post-secondary. Later maybe do weighted averages between complete and incomplete)

g Education=""
replace Education="prim" if edulevel1==3
replace Education="sec" if edulevel1==5
replace Education="tert" if edulevel1==6

keep if Education!=""
codebook ccode year unemp_rate

g dummy=1 if Education!=""
bysort ccode year: egen NonMissingEdu=total(dummy)
ta NonMissingEdu
codebook ccode if NonMissingEdu==3
keep if NonMissingEdu==3

* keep latest year for which we have information

bysort ccode: egen LatestYear=max(year)
ta year if year==LatestYear
keep if year==LatestYear

codebook ccode year unemp_rate

* rehape to wide format

g i2d2_unemp_male_=unemp_rate
keep ccode year Education i2d2_unemp_male
reshape wide i2d2_unemp_male year, i(ccode) j(Education) string
drop yearsec yeartert
rename yearprim i2d2_ActualYear
g year=2013
label variable i2d2_ActualYear "Year in which underlying survey was collected"
rename ccode countrycode

save "${outdir}/i2d2.dta", replace

log close
